package top.starp.LeetCode.test1;

import java.util.Arrays;

public class Solution {
    public int coinChange(int[] coins, int amount) {
        if (amount < 1) {
            return 0;
        }
        return coinChange(coins, amount, new int[amount]);
    }

    private int coinChange(int[] coins, int rem, int[] count) {
        if (rem < 0) {
            return -1;
        }
        if (rem == 0) {
            return 0;
        }
        if (count[rem - 1] != 0) {
            return count[rem - 1];
        }
        int min = Integer.MAX_VALUE;
        for (int coin : coins) {
            int res = coinChange(coins, rem - coin, count);
            if (res >= 0 && res < min) {
                min = 1 + res;
            }
        }
        count[rem - 1] = (min == Integer.MAX_VALUE) ? -1 : min;
        return count[rem - 1];
    }
    public static void main(String[] args){
        Solution a=new Solution();
        int[] arr= new int[]{1,2,3};
//        arr.to
        System.out.println(Arrays.toString(arr));
        a.coinChange(new int[]{1,2,3},11);
        //    Solution a = new coinChange([1,2,3],11);
        //        a.coinChange(Arrays.asList(1,2,3),11);


    }

}
